function Menu(obj) {
	UiElement.call(this, obj, "ul");
	var act = false;
	this.isActivate = function() {
		return act;
	}
	this.setActivate = function(acte) {
		act = acte;
	}
	this.isMenuBar = function() {
		return true;
	}
	return this;
}

function MenuItem(obj) {
	var pObj = eles[obj.parentId];
	var tmp = pObj.items;
	var img = createMenuItemImg(obj);
	this.isActivate = function() {
		return pObj.isActivate();
	}
	this.setActivate = function(acte) {
		pObj.setActivate(acte);
	}
	this.isMenuBar = function() {
		return false;
	}
	this.flushPosition = function(tc) {
		if (pObj.isMenuBar()) {
			this.ul.style.top = (tc.offsetTop + tc.offsetHeight) + "px";
			this.ul.style.left = tc.offsetLeft + "px";
		} else {
			this.ul.style.top = tc.offsetTop + "px";
			this.ul.style.left = (tc.offsetLeft + tc.offsetWidth) + "px";
		}
	}
	UiElement.call(this, obj, "li");

	var div = createElement('div');
	div.innerText = obj.title;
	if (pObj.isMenuBar()) {
		img.style["display"] = "none";
		this.uiEle.style.float = "left";
	} else {
		if (eles[obj.parentId].ul) {
		} else {
			pObj.ul = createMenuItemUl(obj);
			addEles(obj.parentId, [ pObj.ul ]);
			expandEvent(pObj);
		}
		addEles(pObj.ul.id, [ this.uiEle ]);
	}
	addEles(obj.id, [ img, div ]);
	this.items = [ img, div ];
	return this;
}

function expandEvent(pObj) {
	pObj.expand = false;
	var cEle = pObj.uiEle;
	addEvent(cEle, "click", function() {
		if (pObj.expand == false) {
			if (triggerEventEle().parentNode.id == "") {
				return;
			}
		}
		pObj.setActivate(!pObj.isActivate())
		if (pObj.isActivate()) {
			expandMenuItem(pObj);
			pObj.flushPosition(this);
		} else {
			if (pObj.isActivate() == false) {
				expandMenuItem(pObj);
				var to = eles[pObj.parent];
				while (to.isMenuBar() == false) {
					to.ul.style["display"] = "none";
					to.expand = false;
					to = eles[to.parent];
				}
			}
		}
	});
	addEvent(cEle, "mouseenter", function() {
		if (pObj.isActivate() == false) {
			return;
		}
		pObj.flushPosition(this);
		expandMenuItem(pObj);
	});
	addEvent(cEle, "mouseleave", function() {
		if (pObj.isActivate() == false) {
			return;
		}
		expandMenuItem(pObj);
	});
}

function createMenuItemUl(obj) {
	var ul = createElement('ul');
	ul.id = obj.id + "ul";
	ul.setAttribute("class", "menuUl");
	return ul;
}
function createMenuItemImg(obj) {
	var img = createElement('img');
	img.setAttribute("class", "menuImg");
	return img;
}
function expandMenuItem(obj) {
	obj.ul.style["display"] = obj.expand ? "none" : "block";
	obj.expand = !obj.expand;
}
